package com.hl.card.modular.pack.controller;

import com.hl.card.common.persistence.model.DisMemberInfo;
import com.hl.card.common.util.CommonUtil;
import com.hl.card.common.util.ResponseData;
import com.hl.card.common.util.ResponseObject;
import com.hl.card.modular.pack.service.DisMemberInfoService;
import com.hl.card.modular.packBack.service.IMarketingManageService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 合伙人申请资料控制器
 * 
 * @author 袁伟
 *
 */
@RestController
@RequestMapping("/api/disMemberInfo")
public class MemberInfoController {
	@Autowired
	private DisMemberInfoService disMemberInfoService;
	@Autowired
	private IMarketingManageService iMarketingManageService;
	@Autowired
	private ResponseData responseData;
	
	/**
	 * 修改支付密码
	 * 
	 * @param order
	 * @return
	 */
	@GetMapping(value = "/modifyDisPayPassword")

	public ResponseData modifyDisPayPassword(String disUserId, String disPayPassword,String newPassword) {
		responseData.setData(null);
		ResponseObject res = new ResponseObject();
		/* DisMemberInfo dmi= new DisMemberInfo(); */
		if (CommonUtil.isEmpty(disPayPassword)) {
			responseData.setStatus("0");
			responseData.setMsg("支付密码不能为空");
			return responseData;
		}
		if (CommonUtil.isEmpty(newPassword)) {
			responseData.setStatus("0");
			responseData.setMsg("新建密码不能为空");
			return responseData;
		}
		DisMemberInfo seqId = disMemberInfoService.selectDisMemberInfo(disUserId, disPayPassword);
		/* if (seqId.getDisPayPassword()==disPayPassword) { */
		if (seqId.getDisPayPassword().equals(disPayPassword)) {			 
		} else {
			responseData.setStatus("2");
			responseData.setData("输入的旧密码错误！请重新输入。");
			return responseData;

		}
		if (seqId.getDisPayPassword().equals(newPassword)) {			 
			responseData.setStatus("3");
			responseData.setData("旧密码与新密码相同！请重新输入。");
			return responseData;

		}
		return disMemberInfoService.updateDisPayPasswordById(disUserId, newPassword);

	}
	/**
	 * 查询支付密码and保存支付密码
	 * 
	 * @param order
	 * @return
	 */
	@GetMapping(value = "/saveDisPayPassword")
	public ResponseData selectDisPayPassword(String disUserId, String disPayPassword) {
		responseData.setData(null);
		ResponseObject res = new ResponseObject();
		if (CommonUtil.isEmpty(disUserId)) {
			responseData.setStatus("0");
			responseData.setMsg("用户Id不得能为空");
			return responseData;
		}if (CommonUtil.isEmpty(disPayPassword)) {
			responseData.setStatus("0");
			responseData.setMsg("密码不得能为空");
			return responseData;
		}
		 DisMemberInfo seqId = disMemberInfoService.selectDisMemberInfo(disUserId, disPayPassword);
		 if (seqId.getDisPayPassword()==null&&seqId.getDisPayPassword()=="") {	
			 responseData.setStatus("0");
			 responseData.setData("您好！您还没有创建支付密码，请创建！");
			 return responseData;
			}
		return disMemberInfoService.saveDisPayPassword(disUserId, disPayPassword);
	}
	/**
	 * 查询支付密码状态
	 * 
	 * @param order
	 * @return
	 */
	@GetMapping(value = "/selectDisPayPasswordState")
	@ResponseBody
	public ResponseObject selectDisPayPasswordState(String disPayPassword,String disUserId) {
		ResponseObject res = new ResponseObject();
		 DisMemberInfo seqId = disMemberInfoService.selectDisMemberInfo(disUserId,disPayPassword);
			if (StringUtils.isBlank( seqId.getDisUserId())) {
				res.setErroCode(0);
				res.setData("没有此用户");
				
			}if (StringUtils.isBlank(seqId.getDisPayPassword())) {				
				System.out.println("用户没有密码状态");		
				res.setErroCode(1);
				res.setData("用户没有密码状态");
			}else {
				System.out.println("用户有密码状态");				
				res.setErroCode(2);
				res.setData(seqId.getDisPayPassword());
			}
		
		return res;
 
	}
	/**
	 * 连续签到 赠送比豆
	 * @param continuous
	 * @return res
	 */
	
	@PostMapping(value = "/seletOfMarketing")
	@ResponseBody
	public ResponseObject seletOfMarketing() {
		ResponseObject res = new ResponseObject();
		 Object seqId = iMarketingManageService.seletOfMarketing();
			if (seqId==null&&seqId=="") {
				res.setErroCode(1);
				res.setData("签到状态失败");
				
			}else {
				res.setErroCode(2);
				res.setData(seqId);
			}
			System.out.println("每日签到的状态为"+seqId.toString());
		return res;
 
	}
}
